package com.jeewms.www.tms.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.jeewms.www.tms.bean.vm.DemoVm;
import com.jeewms.www.tms.bean.vm.wmi1entity;
import com.jeewms.www.tms.constance.ClassHolder;
import com.jeewms.www.tms.constance.Constance;
import com.jeewms.www.tms.ui.itemview.DemoItemView;
import com.jeewms.www.tms.ui.itemview.PandianItemView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 13799 on 2018/8/5.
 */

public class DemoAdapter extends BaseAdapter {

    Context mContext;
    private int type;
    private String typeName="";
    private String className="";

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    private List<DemoVm> list = new ArrayList<>();
    private List<wmi1entity> wmi1List = new ArrayList<wmi1entity>();

    public List<wmi1entity> getWmi1List() {
        return wmi1List;
    }

    public void setWmi1List(List<wmi1entity> wmi1List) {
        this.wmi1List = wmi1List;
    }

    public DemoAdapter(Context context) {
        mContext = context;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public List<DemoVm> getList() {
        return list;
    }

    public void setList(List<DemoVm> list) {
        this.list = list;
    }


    @Override
    public int getCount() {
        if (type == 0)
            return list == null ? 0 : list.size();
        else
            return wmi1List == null ? 0 : wmi1List.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (className.equals(ClassHolder.PANDIAN)) {
            PandianItemView itemView = null;
            if (view == null) {
                itemView = new PandianItemView(mContext);
                view = itemView.getmView();
                view.setTag(itemView);
            } else {
                itemView = (PandianItemView) view.getTag();
            }
            itemView.bind(list.get(i), i, className, typeName);
            itemView.setListent(new PandianItemView.InventoryListent() {
                @Override
                public void save(int position) {
//                remove(position);
                }

                @Override
                public void saveVm(int position, String x5, String x6, String x7) {
                    list.get(position).setWmX7(x5);
                    list.get(position).setWmX8(x6);
                    list.get(position).setWmX9(x7);
                }
            });
        } else {
            DemoItemView itemView = null;
            if (view == null) {
                itemView = new DemoItemView(mContext);
                view = itemView.getmView();
                view.setTag(itemView);
            } else {
                itemView = (DemoItemView) view.getTag();
            }
            if (type == 0)
                itemView.bind(list.get(i), i, type, className);
            else
                itemView.bind(wmi1List.get(i), i, type, className);
        }
        return view;
    }
}
